<template>
  <div>
      <el-dialog
        title="查询"
        :visible.sync="dialogVisible"
        width="30%"
        :before-close="handleClose">
        <el-form label-width="80px"  :rules='rules' ref="ruleForm" :model="ruleForm" >
          <el-form-item label="日期"  prop="mySearch">
            <el-input v-model="ruleForm.mySearch"></el-input>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click=" submitForm('ruleForm')">确 定</el-button>
        </span>
      </el-dialog>
  </div>
</template>

<script>
import eventBus from "../../../utils/eventBus"
export default {
  data() {
      return {
        dialogVisible: false,
        ruleForm:{
          mySearch:'',
        },
        rules: {
          mySearch: [
            { required: true, message: '请输入正确的时间格式;YYYY-MM-DD', trigger: 'blur' },
          ],
        }
      };
    },
    mounted(){
      eventBus.$on("dialogChange",(val)=>{
        this.dialogVisible =val
      })
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.dialogVisible = false
            this.$emit("parentSearch",this.ruleForm.mySearch) 
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      },
      handleClose(done) {
        this.$confirm('确认关闭？')
          .then(_ => {
            done();
          })
          .catch(_ => {});
      }
    }
  };

</script>

<style>

</style>